<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="##XMPPFramework ####1. 导入源码1). 将下载好的XMPPFramework解压，解压后的目录如下：">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="XMPPFramework-使用(Mac)">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/IM/XMPPFramework-使用(Mac)/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="##XMPPFramework ####1. 导入源码1). 将下载好的XMPPFramework解压，解压后的目录如下：">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-50f17328b7d01f9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-106dda50d4c85fc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-8d2c189576fe945d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-ecbe82c9a6fe550f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-085232d38e5d8134.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-4f9506abf27bd80d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-5c7b331f45bb8598.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-5e921afda0432000.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-c42d53cd6ae1d50f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-b4253a5b23895ad3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-6cd3b969c54339b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-41704530f307c687.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-06356be41ed12033.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-06T11:02:54.012Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="XMPPFramework-使用(Mac)">
<meta name="twitter:description" content="##XMPPFramework ####1. 导入源码1). 将下载好的XMPPFramework解压，解压后的目录如下：">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/3110861-50f17328b7d01f9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/IM/XMPPFramework-使用(Mac)/"/>





  <title>XMPPFramework-使用(Mac) | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/IM/XMPPFramework-使用(Mac)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">XMPPFramework-使用(Mac)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>##<a href="https://github.com/robbiehanson/XMPPFramework" target="_blank" rel="noopener">XMPPFramework</a></p>
<p>####1. 导入源码<br>1). 将下载好的XMPPFramework解压，解压后的目录如下：<br><img src="http://upload-images.jianshu.io/upload_images/3110861-50f17328b7d01f9c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1.png"></p>
<a id="more"></a>
<p>2). 将Sample_XMPPFramework.h更名为XMPPFramework.h，然后将XMPPFramework-3.6.4文件夹直接拖入要使用该框架的工程中，然后删除将XMPPFramwork-3.6.4文件夹中的文件夹(除Xcode文件夹)及XMPPFramework.h文件保留，其他文件删除，删除后结构如图3，编译。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-106dda50d4c85fc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图2.png"><br><img src="http://upload-images.jianshu.io/upload_images/3110861-8d2c189576fe945d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图3.png"></p>
<p>3). 解决错误I<br><img src="http://upload-images.jianshu.io/upload_images/3110861-ecbe82c9a6fe550f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图4.png"><br><strong>解决办法:</strong></p>
<ul>
<li>在Build Settings 搜索Header Search Paths 添加头文件搜索路径： <code>/usr/include/libxml2</code></li>
<li>在Build Phasses-&gt;Link Binary With Libraries中添加两个动态链接库： <code>libxml2.tbd</code>、<code>libresolv.tbd</code></li>
<li>在Build Settings 搜索prefix Header，在Prefix Header中添加<code>$SRCROOT/$(PRODUCT_NAME)/PrefixHeader.pch</code></li>
<li>在项目的根目录下新建pch文件：Other-&gt;PCH File。</li>
</ul>
<p>4). 编译， 报如下错误：<br><img src="http://upload-images.jianshu.io/upload_images/3110861-085232d38e5d8134.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图5.png"><br><strong>解决办法：</strong></p>
<ul>
<li>在PrefixHeader.pch中添加头文件<code>#import &lt;UIKit/UIKit.h&gt;</code>，添加后内容如下：<br><img src="http://upload-images.jianshu.io/upload_images/3110861-4f9506abf27bd80d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图6.png"></li>
</ul>
<p>5). 编译，此时如果不出现意外，就可以成功编译。但我在编译时出现如下错误：<br><img src="http://upload-images.jianshu.io/upload_images/3110861-5c7b331f45bb8598.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图7.png"><br><strong>问题原因</strong>：重复定义<br><strong>解决办法</strong>：找到对应的位置，将34行注释，因此是重复定义，因此注释之后对源码没有影响。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-5e921afda0432000.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图8.png"></p>
<p>6). 成功编译<br><img src="http://upload-images.jianshu.io/upload_images/3110861-c42d53cd6ae1d50f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图9.png"></p>
<p>####2. 注册与登陆<br>PrefixHeader.pch<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#ifndef PrefixHeader_pch</span><br><span class="line">#define PrefixHeader_pch</span><br><span class="line"></span><br><span class="line">#import &lt;UIKit/UIKit.h&gt;</span><br><span class="line">#import &quot;XMPPFramework.h&quot;</span><br><span class="line">#import &quot;MTStreamManager.h&quot;</span><br><span class="line"></span><br><span class="line">#endif</span><br></pre></td></tr></table></figure></p>
<p>MTStreamManager.h<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">#import &lt;Foundation/Foundation.h&gt;</span><br><span class="line"></span><br><span class="line">@interface MTStreamManager : NSObject</span><br><span class="line"></span><br><span class="line">typedef NS_ENUM(NSInteger, connectToServer) &#123;</span><br><span class="line">    connectToSerLogin, // 登陆</span><br><span class="line">    connectToSerRegist // 注册</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// 单例</span><br><span class="line">+ (instancetype) sharedManager;</span><br><span class="line"></span><br><span class="line">// 创建XMPPStream流</span><br><span class="line">@property (nonatomic, strong) XMPPStream *xmppStream;</span><br><span class="line"></span><br><span class="line">// 存储密码</span><br><span class="line">@property (nonatomic, copy) NSString *password;</span><br><span class="line"></span><br><span class="line">// 区别注册还是登陆</span><br><span class="line">@property (nonatomic) connectToServer connectStatus;</span><br><span class="line"></span><br><span class="line">// 注册</span><br><span class="line">- (void) registWithName:(NSString *)name andPassword:(NSString *)password;</span><br><span class="line"></span><br><span class="line">// 登陆</span><br><span class="line">- (void) loginWithName:(NSString *)name andPassword:(NSString *)password;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>MTStreamManager.m<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#import &quot;MTStreamManager.h&quot;</span><br><span class="line">// 打印日志需要</span><br><span class="line">#import &quot;DDLog.h&quot;</span><br><span class="line">#import &quot;DDTTYLogger.h&quot;</span><br><span class="line">#import &quot;XMPPLogging.h&quot;</span><br><span class="line"></span><br><span class="line">#define DO_MAIN @&quot;mazaiting.com&quot;</span><br><span class="line"></span><br><span class="line">@interface MTStreamManager() &lt;XMPPStreamDelegate&gt;</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTStreamManager</span><br><span class="line">static MTStreamManager *sInstance;</span><br><span class="line">// 单例</span><br><span class="line">+ (instancetype) sharedManager &#123;</span><br><span class="line">    static dispatch_once_t onceToken;</span><br><span class="line">    dispatch_once(&amp;onceToken, ^&#123;</span><br><span class="line">        sInstance = [MTStreamManager new];</span><br><span class="line">        // 设置日志打印</span><br><span class="line">        [DDLog addLogger:[DDTTYLogger sharedInstance]];</span><br><span class="line">        // 设置日志等级</span><br><span class="line">        [DDLog setLogLevel:XMPP_LOG_FLAG_SEND_RECV forClass:self];</span><br><span class="line">    &#125;);</span><br><span class="line">    return sInstance;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 懒加载XMPPStream</span><br><span class="line">- (XMPPStream *)xmppStream &#123;</span><br><span class="line">    if (nil == _xmppStream) &#123;</span><br><span class="line">        // 创建</span><br><span class="line">        _xmppStream = [[XMPPStream alloc] init];</span><br><span class="line">        // 设置属性</span><br><span class="line">        // ip</span><br><span class="line">        _xmppStream.hostName = @&quot;127.0.0.1&quot;;</span><br><span class="line">        // 端口</span><br><span class="line">        _xmppStream.hostPort = 5222;</span><br><span class="line">        // 设置代理--多播代理</span><br><span class="line">        [_xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppStream;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 注册</span><br><span class="line">- (void) registWithName:(NSString *)name andPassword:(NSString *)password &#123;</span><br><span class="line">    // 创建一个JID</span><br><span class="line">    XMPPJID *jid = [XMPPJID jidWithUser:name domain:DO_MAIN resource:nil];</span><br><span class="line">    // 设置MyJID</span><br><span class="line">    [self.xmppStream setMyJID:jid];</span><br><span class="line">    // 设置密码</span><br><span class="line">    self.password = password;</span><br><span class="line">    // 设置状态为注册</span><br><span class="line">    self.connectStatus = connectToSerRegist;</span><br><span class="line">    // 连接到服务器</span><br><span class="line">    [self connectServer];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 登陆</span><br><span class="line">- (void) loginWithName:(NSString *)name andPassword:(NSString *)password &#123;</span><br><span class="line">    // 创建一个JID</span><br><span class="line">    XMPPJID *jid = [XMPPJID jidWithUser:name domain:DO_MAIN resource:nil];</span><br><span class="line">    // 设置MyJID</span><br><span class="line">    [self.xmppStream setMyJID:jid];</span><br><span class="line">    // 设置密码</span><br><span class="line">    self.password = password;</span><br><span class="line">    // 设置状态为注册</span><br><span class="line">    self.connectStatus = connectToSerLogin;</span><br><span class="line">    // 连接到服务器</span><br><span class="line">    [self connectServer];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 连接到服务器</span><br><span class="line">- (void)connectServer &#123;</span><br><span class="line">    // 判断当前是否有连接，如果有则断开</span><br><span class="line">    if ([self.xmppStream isConnected]) &#123;</span><br><span class="line">        // 退出登陆</span><br><span class="line">        [self logout];</span><br><span class="line">    &#125;</span><br><span class="line">    // 异常信息</span><br><span class="line">    NSError *error = nil;</span><br><span class="line">    // 连接服务器</span><br><span class="line">    [self.xmppStream connectWithTimeout:15.0f error:&amp;error];</span><br><span class="line">    // 判断是否连接成功</span><br><span class="line">    if (error) &#123;</span><br><span class="line">        NSLog(@&quot;连接失败&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 退出登陆</span><br><span class="line">- (void) logout &#123;</span><br><span class="line">    // 用户状态类</span><br><span class="line">    XMPPPresence *presence = [XMPPPresence presenceWithType:@&quot;unavailable&quot;];</span><br><span class="line">    // 向服务器发送离线通知</span><br><span class="line">    [self.xmppStream sendElement:presence];</span><br><span class="line">    // 断开连接</span><br><span class="line">    [self.xmppStream disconnect];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark 代理方法，连接成功之后回调</span><br><span class="line">- (void)xmppStreamDidConnect:(XMPPStream *)sender &#123;</span><br><span class="line">    switch (self.connectStatus) &#123;</span><br><span class="line">        case connectToSerLogin:</span><br><span class="line">        &#123;</span><br><span class="line">            // 错误</span><br><span class="line">            NSError *error = nil;</span><br><span class="line">            // 登陆</span><br><span class="line">            [self.xmppStream authenticateWithPassword:self.password error:&amp;error];</span><br><span class="line">            // 匿名登陆</span><br><span class="line">//            [self.xmppStream authenticateAnonymously:&amp;error];</span><br><span class="line">            // 判断是否登陆成功</span><br><span class="line">            if (error) &#123;</span><br><span class="line">                NSLog(@&quot;登陆失败&quot;);</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                NSLog(@&quot;登陆成功&quot;);</span><br><span class="line">                // 登陆成功之后注册其他模块</span><br><span class="line">                [self activite];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">            break;</span><br><span class="line">        case connectToSerRegist:</span><br><span class="line">        &#123;</span><br><span class="line">            // 错误</span><br><span class="line">            NSError *error = nil;</span><br><span class="line">            // 注册</span><br><span class="line">            [self.xmppStream registerWithPassword:self.password error:&amp;error];</span><br><span class="line">            // 判断是否注册成功</span><br><span class="line">            if (error) &#123;</span><br><span class="line">                NSLog(@&quot;注册失败&quot;);</span><br><span class="line">            &#125;</span><br><span class="line">            // 注册成功之后断开连接</span><br><span class="line">            [self logout];</span><br><span class="line">        &#125;</span><br><span class="line">            break;</span><br><span class="line">        default:</span><br><span class="line">            break;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark 代理方法，登陆成功之后告诉服务器我要出席</span><br><span class="line">- (void)xmppStreamDidAuthenticate:(XMPPStream *)sender &#123;</span><br><span class="line">    // 如果成功，可以出席</span><br><span class="line">    XMPPPresence *presence = [XMPPPresence presence];</span><br><span class="line">    // 添加出席状态</span><br><span class="line">    [presence addChild:[DDXMLElement elementWithName:@&quot;show&quot; stringValue:@&quot;dnd&quot;]];</span><br><span class="line">    [presence addChild:[DDXMLElement elementWithName:@&quot;status&quot; stringValue:@&quot;请勿打扰&quot;]];</span><br><span class="line">    // 告诉服务器我要出席</span><br><span class="line">    [self.xmppStream sendElement:presence];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>ViewController.m<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">#import &quot;ViewController.h&quot;</span><br><span class="line"></span><br><span class="line">@interface ViewController ()</span><br><span class="line">// 用户名输入框</span><br><span class="line">@property (weak, nonatomic) IBOutlet UITextField *userName;</span><br><span class="line">// 密码输入框</span><br><span class="line">@property (weak, nonatomic) IBOutlet UITextField *passWord;</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation ViewController</span><br><span class="line">// 注册</span><br><span class="line">- (IBAction)regist:(id)sender &#123;</span><br><span class="line">    NSString *username = self.userName.text;</span><br><span class="line">    NSString *password = self.passWord.text;</span><br><span class="line">    [[MTStreamManager sharedManager] registWithName:username andPassword:password];</span><br><span class="line">&#125;</span><br><span class="line">// 登陆</span><br><span class="line">- (IBAction)login:(id)sender &#123;</span><br><span class="line">    NSString *username = self.userName.text;</span><br><span class="line">    NSString *password = self.passWord.text;</span><br><span class="line">    [[MTStreamManager sharedManager] loginWithName:username andPassword:password];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>注册后可在管理控制台中查看<br><img src="http://upload-images.jianshu.io/upload_images/3110861-b4253a5b23895ad3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图10.png"></p>
<p>####3. 断线重连<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 自动重连</span><br><span class="line">#import &quot;XMPPReconnect.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 在MTStreamManager.h中添加属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 创建自动重连对象</span><br><span class="line">@property (nonatomic, strong) XMPPReconnect *xmppReconnect;</span><br></pre></td></tr></table></figure></p>
<p>3). 在MTStreamManager.m中懒加载xmppReconnect<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">// 懒加载断线重连</span><br><span class="line">- (XMPPReconnect *)xmppReconnect &#123;</span><br><span class="line">    if (nil == _xmppReconnect) &#123;</span><br><span class="line">        // 创建对象</span><br><span class="line">        _xmppReconnect = [[XMPPReconnect alloc] initWithDispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">        // 设置参数</span><br><span class="line">        _xmppReconnect.reconnectTimerInterval = 2;</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppReconnect;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>4). 在XMPPFramework.m中的activite方法中进行激活<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    // 激活断线重连</span><br><span class="line">    [self.xmppReconnect activate:self.xmppStream];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>5). 测试方法<br>进入管理控制台中，选择会话，把登陆的用户点击右侧的关闭连接将其断开，然后刷新页面，如果成功登陆，则断线重连功能完成。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-6cd3b969c54339b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图11.png"></p>
<p>####4. 心跳检测<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 心跳检测</span><br><span class="line">#import &quot;XMPPAutoPing.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 在MTStreamManager.h中添加属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 创建心跳检测对象</span><br><span class="line">@property (nonatomic, strong) XMPPAutoPing *xmppAutoPing;</span><br></pre></td></tr></table></figure></p>
<p>3). 在MTStreamManager.m中懒加载xmppAutoPing<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">// 心跳检测</span><br><span class="line">- (XMPPAutoPing *)xmppAutoPing &#123;</span><br><span class="line">    if (nil == _xmppAutoPing) &#123;</span><br><span class="line">        // 创建心跳检测</span><br><span class="line">        _xmppAutoPing = [[XMPPAutoPing alloc] initWithDispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">        // 设置参数</span><br><span class="line">        _xmppAutoPing.pingInterval = 3;</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppAutoPing;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>4). 在XMPPFramework.m中的activite方法中进行激活<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    // 激活断线重连</span><br><span class="line">    [self.xmppReconnect activate:self.xmppStream];</span><br><span class="line">    // 激活心跳检测</span><br><span class="line">    [self.xmppAutoPing activate:self.xmppStream];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>5). 测试方法<br>运行程序后查看控制台打印，如果一直在不断的刷新，则证明心跳检测开启。</p>
<p>####5. 好友功能模块<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 好友角色</span><br><span class="line">#import &quot;XMPPRoster.h&quot;</span><br><span class="line">// 好友存储管理</span><br><span class="line">#import &quot;XMPPRosterCoreDataStorage.h&quot;</span><br><span class="line">// 好友的实体</span><br><span class="line">#import &quot;XMPPUserCoreDataStorageObject.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 在MTStreamManager.h中添加属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 创建好友列表功能模块</span><br><span class="line">@property (nonatomic, strong) XMPPRoster *xmppRoster;</span><br></pre></td></tr></table></figure></p>
<p>3). 在MTStreamManager.m中懒加载xmppRoster<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">// 好友列表功能</span><br><span class="line">- (XMPPRoster *)xmppRoster &#123;</span><br><span class="line">    if (nil == _xmppRoster) &#123;</span><br><span class="line">        // 创建对象</span><br><span class="line">        _xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:[XMPPRosterCoreDataStorage sharedInstance] dispatchQueue:dispatch_get_global_queue(0, 0)];</span><br><span class="line">        // 设置参数</span><br><span class="line">        // 是否自动查找新的好友数据</span><br><span class="line">        _xmppRoster.autoFetchRoster = YES;</span><br><span class="line">        // 是否自动删除用户存储的数据，不需要</span><br><span class="line">        _xmppRoster.autoClearAllUsersAndResources = NO;</span><br><span class="line">        // 如果自动接收XMPP,会帮我们做一个加好友的操作，代理方法也不会被调用了</span><br><span class="line">        _xmppRoster.autoAcceptKnownPresenceSubscriptionRequests = NO;</span><br><span class="line">        //设置代理，，注意让MTStreamManager实现XMPPRosterDelegate协议</span><br><span class="line">        [_xmppRoster addDelegate:self delegateQueue:dispatch_get_global_queue(0, 0)];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppRoster;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>4). 在XMPPFramework.m中的activite方法中进行激活<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    // 激活断线重连</span><br><span class="line">    [self.xmppReconnect activate:self.xmppStream];</span><br><span class="line">    // 激活心跳检测</span><br><span class="line">    [self.xmppAutoPing activate:self.xmppStream];</span><br><span class="line">    // 激活好友模块</span><br><span class="line">    [self.xmppRoster activate:self.xmppStream];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>5). 使用</p>
<ul>
<li>使用查询控制器来查询数据<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line">@interface MTContactTableViewController () &lt;NSFetchedResultsControllerDelegate&gt;</span><br><span class="line">// 查询控制器，用来查询好友</span><br><span class="line">@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;</span><br><span class="line">// 好友列表数组</span><br><span class="line">@property (nonatomic, strong) NSArray *contactArrs;</span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTContactTableViewController</span><br><span class="line"></span><br><span class="line">// 懒加载联系人数组</span><br><span class="line">- (NSArray *)contactArrs &#123;</span><br><span class="line">    if (nil == _contactArrs) &#123;</span><br><span class="line">        _contactArrs = [NSArray array];</span><br><span class="line">    &#125;</span><br><span class="line">    return _contactArrs;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 懒加载fetchedResultsController，执行查询操作</span><br><span class="line">- (NSFetchedResultsController *)fetchedResultsController &#123;</span><br><span class="line">    if (nil == _fetchedResultsController) &#123;</span><br><span class="line">        // 创建一个查询请求</span><br><span class="line">        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];</span><br><span class="line">        // 实体</span><br><span class="line">        NSEntityDescription *entity = [NSEntityDescription entityForName:@&quot;XMPPUserCoreDataStorageObject&quot; inManagedObjectContext:[XMPPRosterCoreDataStorage sharedInstance].mainThreadManagedObjectContext];</span><br><span class="line">        // 谓词, 查询只有双方都是对方的好友的人</span><br><span class="line">        NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;subscription = %@&quot;, @&quot;both&quot;];</span><br><span class="line">        // 排序, 根据jidStr进行升序排列</span><br><span class="line">        NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@&quot;jidStr&quot; ascending:YES];</span><br><span class="line">        // 设置实体</span><br><span class="line">        fetchRequest.entity = entity;</span><br><span class="line">        // 设置谓词</span><br><span class="line">        fetchRequest.predicate = predicate;</span><br><span class="line">        // 设置排序</span><br><span class="line">        fetchRequest.sortDescriptors = @[sortDescriptor];</span><br><span class="line">        // 创建fetchedResultsController对象</span><br><span class="line">        _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[XMPPRosterCoreDataStorage sharedInstance].mainThreadManagedObjectContext sectionNameKeyPath:nil cacheName:@&quot;contacts&quot;];</span><br><span class="line">        // 设置代理, 实现协议NSFetchedResultsControllerDelegate</span><br><span class="line">        _fetchedResultsController.delegate = self;</span><br><span class="line">    &#125;</span><br><span class="line">    return _fetchedResultsController;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    </span><br><span class="line">    // 删除CoreData中的缓存</span><br><span class="line">    [NSFetchedResultsController deleteCacheWithName:@&quot;contacts&quot;];</span><br><span class="line">    // 好友代理设置, 实现XMPPRosterDelegate</span><br><span class="line">    [[MTStreamManager sharedManager].xmppRoster addDelegate:self delegateQueue:dispatch_get_global_queue(0, 0)];</span><br><span class="line">    // 执行查询操作, 查询到之后将数据保存在了fetchedObjects变量中</span><br><span class="line">    [self.fetchedResultsController performFetch:nil];</span><br><span class="line">    // 获取到数据</span><br><span class="line">    self.contactArrs = self.fetchedResultsController.fetchedObjects;</span><br><span class="line">    // 刷新数据</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line">#pragma mark - NSFetchedResultsController协议</span><br><span class="line">// 当CoreData数据发生变化会调用该代理方法</span><br><span class="line">- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller &#123;</span><br><span class="line">    NSLog(@&quot;数据发生改变&quot;);</span><br><span class="line">    // 最新的列表</span><br><span class="line">    self.contactArrs = self.fetchedResultsController.fetchedObjects;</span><br><span class="line">    // 刷新数据</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark - Table view data source</span><br><span class="line">// 返回TableView中的条目总数</span><br><span class="line">- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section &#123;</span><br><span class="line">    return self.contactArrs.count;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 设置TableViewCell的高度</span><br><span class="line">- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath &#123;</span><br><span class="line">    return 80.0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 为TableViewCell赋值</span><br><span class="line">- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath &#123;</span><br><span class="line">    // 获取TableViewCell</span><br><span class="line">    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@&quot;Contact_Cell&quot;];</span><br><span class="line">    // 获取对应行的联系人数据</span><br><span class="line">    XMPPUserCoreDataStorageObject *contact = self.contactArrs[indexPath.row];</span><br><span class="line">    </span><br><span class="line">    // 给Cell赋值</span><br><span class="line">    // 设置JID</span><br><span class="line">    UILabel *nameLabel = (UILabel *)[cell viewWithTag:1002];</span><br><span class="line">    nameLabel.text = contact.jidStr;</span><br><span class="line"></span><br><span class="line">    return cell;</span><br><span class="line">&#125;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>6). 添加删除好友</p>
<ul>
<li><p>主动申请添加好友</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">    // 创建XMPPJID</span><br><span class="line">    XMPPJID *jid = [XMPPJID jidWithUser:@&quot;linghaoyu9&quot; domain:DO_MAIN resource:nil];</span><br><span class="line">    // 添加好友</span><br><span class="line">//    [[MTStreamManager sharedManager].xmppRoster addUser:jid withNickname:@&quot;加好友&quot;];</span><br><span class="line">    [[MTStreamManager sharedManager].xmppRoster subscribePresenceToUser:jid];</span><br></pre></td></tr></table></figure>
</li>
<li><p>同意对方的请求</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// 创建XMPPJID</span><br><span class="line">XMPPJID *jid = [XMPPJID jidWithUser:@&quot;linghaoyu9&quot; domain:DO_MAIN resource:nil];</span><br><span class="line">// 同意添加对方为好友</span><br><span class="line">[[MTStreamManager sharedManager].xmppRoster acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除好友</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">    // 创建XMPPJID</span><br><span class="line">    XMPPJID *jid = [XMPPJID jidWithUser:@&quot;linghaoyu9&quot; domain:DO_MAIN resource:nil];</span><br><span class="line">// 删除好友</span><br><span class="line">        [[MTStreamManager sharedManager].xmppRoster removeUser:jid];</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>####6. 聊天模块<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">// 聊天模块</span><br><span class="line">#import &quot;XMPPMessageArchiving.h&quot;</span><br><span class="line">// 聊天信息的存储管理</span><br><span class="line">#import &quot;XMPPMessageArchivingCoreDataStorage.h&quot; </span><br><span class="line">// 消息实体</span><br><span class="line">#import &quot;XMPPMessageArchiving_Message_CoreDataObject.h&quot;</span><br><span class="line">// 最近联系人实体</span><br><span class="line">#import &quot;XMPPMessageArchiving_Contact_CoreDataObject.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 在MTStreamManager.h中添加属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">// 创建聊天功能模块</span><br><span class="line">@property (nonatomic, strong) XMPPMessageArchiving *xmppMessageArchiving;</span><br></pre></td></tr></table></figure></p>
<p>3). 在MTStreamManager.m中懒加载xmppMessageArchiving<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">// 消息模块</span><br><span class="line">- (XMPPMessageArchiving *)xmppMessageArchiving &#123;</span><br><span class="line">    if (nil == _xmppMessageArchiving) &#123;</span><br><span class="line">        // 创建对象</span><br><span class="line">        _xmppMessageArchiving = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:[XMPPMessageArchivingCoreDataStorage sharedInstance] dispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppMessageArchiving;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>4). 在XMPPFramework.m中的activite方法中进行激活<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    // 激活断线重连</span><br><span class="line">    [self.xmppReconnect activate:self.xmppStream];</span><br><span class="line">    // 激活心跳检测</span><br><span class="line">    [self.xmppAutoPing activate:self.xmppStream];</span><br><span class="line">    // 激活好友模块</span><br><span class="line">    [self.xmppRoster activate:self.xmppStream];</span><br><span class="line">    // 激活聊天模块</span><br><span class="line">    [self.xmppMessageArchiving activate:self.xmppStream];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>5). 实现XMPPStreamDelegate协议中的xmppStream:didReceiveMessage:方法, 用来接收消息</p>
<ul>
<li><p>MTStreamManager.m中</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">// 通过代理接收数据</span><br><span class="line">- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message &#123;</span><br><span class="line">    NSLog(@&quot;接收到的消息: %@&quot;, message.body);</span><br><span class="line">    // 发送本地通知，在AppDelegate中接收通知</span><br><span class="line">    UILocalNotification *noti = [[UILocalNotification alloc] init];</span><br><span class="line">    [noti setAlertBody:[NSString stringWithFormat:@&quot;来自%@ : %@ 消息&quot;, message.from, message.body]];</span><br><span class="line">    // 设置appicon图标</span><br><span class="line">    [noti setApplicationIconBadgeNumber:1];</span><br><span class="line">    // 弹出本地通知</span><br><span class="line">    [[UIApplication sharedApplication] presentLocalNotificationNow:noti];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>AppDelegate.m</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions &#123;</span><br><span class="line">    // 需要一个用户通知设置, 用来接收通知</span><br><span class="line">    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeAlert|UIUserNotificationTypeBadge categories:nil];</span><br><span class="line">    // 注册</span><br><span class="line">    [[UIApplication sharedApplication] registerUserNotificationSettings:setting];</span><br><span class="line">    return YES;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>6). 查询消息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">@interface MTChatViewController () &lt;NSFetchedResultsControllerDelegate&gt; &#123;</span><br><span class="line">// 消息列表查询控制器</span><br><span class="line">@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;</span><br><span class="line">// 消息数组</span><br><span class="line">@property (nonatomic, strong) NSArray *chatArrs;</span><br><span class="line">&#125;</span><br><span class="line">// -----------------具体实现</span><br><span class="line">// 懒加载数组</span><br><span class="line">- (NSArray *)chatArrs &#123;</span><br><span class="line">    if (nil == _chatArrs) &#123;</span><br><span class="line">        _chatArrs = [NSArray array];</span><br><span class="line">    &#125;</span><br><span class="line">    return _chatArrs;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 懒加载fetchedResultsController</span><br><span class="line">- (NSFetchedResultsController *)fetchedResultsController &#123;</span><br><span class="line">    if (nil == _fetchedResultsController) &#123;</span><br><span class="line">        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];</span><br><span class="line">        NSEntityDescription *entity = [NSEntityDescription entityForName:@&quot;XMPPMessageArchiving_Message_CoreDataObject&quot; inManagedObjectContext:[XMPPMessageArchivingCoreDataStorage sharedInstance].mainThreadManagedObjectContext];</span><br><span class="line">        [fetchRequest setEntity:entity];</span><br><span class="line">        // Specify criteria for filtering which objects to fetch</span><br><span class="line">        NSPredicate *predicate = [NSPredicate predicateWithFormat:@&quot;bareJidStr = %@&quot;, self.userJid.bare];</span><br><span class="line">        [fetchRequest setPredicate:predicate];</span><br><span class="line">        // Specify how the fetched objects should be sorted</span><br><span class="line">        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@&quot;timestamp&quot; ascending:YES];</span><br><span class="line">        [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];</span><br><span class="line">        </span><br><span class="line">        _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[XMPPMessageArchivingCoreDataStorage sharedInstance].mainThreadManagedObjectContext sectionNameKeyPath:nil cacheName:@&quot;messages&quot;];</span><br><span class="line">        </span><br><span class="line">        _fetchedResultsController.delegate = self;</span><br><span class="line">    &#125;</span><br><span class="line">    return _fetchedResultsController;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    // 清除缓存</span><br><span class="line">    [NSFetchedResultsController deleteCacheWithName:@&quot;messages&quot;];</span><br><span class="line">    // 查询聊天记录</span><br><span class="line">    [self.fetchedResultsController performFetch:nil];</span><br><span class="line">    // 数据赋值</span><br><span class="line">    self.chatArrs = self.fetchedResultsController.fetchedObjects;</span><br><span class="line">    // 刷新</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>7). 发送消息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">    // 发消息--私聊</span><br><span class="line">    XMPPMessage *message = [XMPPMessage messageWithType:@&quot;chat&quot; to:self.userJid];</span><br><span class="line">    // 发消息--群聊</span><br><span class="line">//    XMPPMessage *message = [XMPPMessage messageWithType:@&quot;group&quot; to:self.userJid];</span><br><span class="line">    // 设置消息</span><br><span class="line">    [message addBody:self.message.text];</span><br><span class="line">    // 发消息</span><br><span class="line">    [[MTStreamManager sharedManager].xmppStream sendElement:message];</span><br></pre></td></tr></table></figure></p>
<p>8). 获取最近联系人<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">@interface MTRecentlyTableViewController () &lt;NSFetchedResultsControllerDelegate, XMPPvCardAvatarDelegate&gt;</span><br><span class="line">// 控制器查询数据</span><br><span class="line">@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;</span><br><span class="line">// 最近联系人数组</span><br><span class="line">@property (nonatomic, strong) NSArray *recentlyArrs;</span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTRecentlyTableViewController</span><br><span class="line"></span><br><span class="line">// 懒加载数组</span><br><span class="line">- (NSArray *)recentlyArrs &#123;</span><br><span class="line">    if (nil == _recentlyArrs) &#123;</span><br><span class="line">        _recentlyArrs = [NSArray array];</span><br><span class="line">    &#125;</span><br><span class="line">    return _recentlyArrs;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 懒加载控制器</span><br><span class="line">- (NSFetchedResultsController *)fetchedResultsController &#123;</span><br><span class="line">    if (nil == _fetchedResultsController) &#123;</span><br><span class="line">        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];</span><br><span class="line">        NSEntityDescription *entity = [NSEntityDescription entityForName:@&quot;XMPPMessageArchiving_Contact_CoreDataObject&quot; inManagedObjectContext:[XMPPMessageArchivingCoreDataStorage sharedInstance].mainThreadManagedObjectContext];</span><br><span class="line">        [fetchRequest setEntity:entity];</span><br><span class="line">        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@&quot;mostRecentMessageTimestamp&quot; ascending:NO];</span><br><span class="line">        [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];</span><br><span class="line">        // 创建控制器</span><br><span class="line">        _fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[XMPPMessageArchivingCoreDataStorage sharedInstance].mainThreadManagedObjectContext sectionNameKeyPath:nil cacheName:@&quot;Recently&quot;];</span><br><span class="line">        // 设置代理</span><br><span class="line">        _fetchedResultsController.delegate = self;</span><br><span class="line">    &#125;</span><br><span class="line">    return _fetchedResultsController;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// NSFetchedResultsController代理, 当查询的内容发生改变的时候会调用此方法</span><br><span class="line">- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller &#123;</span><br><span class="line">    // 数据获取</span><br><span class="line">    self.recentlyArrs = self.fetchedResultsController.fetchedObjects;</span><br><span class="line">    // 数据刷新</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    // 清楚缓存数据</span><br><span class="line">    [NSFetchedResultsController deleteCacheWithName:@&quot;Recently&quot;];</span><br><span class="line">    // 数据查询</span><br><span class="line">    [self.fetchedResultsController performFetch:nil];</span><br><span class="line">    // 数组赋值</span><br><span class="line">    self.recentlyArrs = self.fetchedResultsController.fetchedObjects;</span><br><span class="line">    // 刷新列表</span><br><span class="line">    [self.tableView reloadData];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####7. 资料模块<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">// 自己个人资料模块</span><br><span class="line">#import &quot;XMPPvCardTempModule.h&quot;</span><br><span class="line">// 个人资料内存存储</span><br><span class="line">#import &quot;XMPPvCardTemp.h&quot;</span><br><span class="line">// 个人资料的存储器,自己和别人</span><br><span class="line">#import &quot;XMPPvCardCoreDataStorage.h&quot;</span><br><span class="line">// 个人资料的实体对象</span><br><span class="line">#import &quot;XMPPvCardCoreDataStorageObject.h&quot;</span><br><span class="line">// 好友的个人资料</span><br><span class="line">#import &quot;XMPPvCardAvatarModule.h&quot;</span><br><span class="line">// 好友个人资料实体对象</span><br><span class="line">#import &quot;XMPPvCardAvatarCoreDataStorageObject.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 在MTStreamManager.h中添加属性<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 自己个人资料的功能类</span><br><span class="line">@property (nonatomic, strong) XMPPvCardTempModule *xmppvCardTempModule;</span><br><span class="line"></span><br><span class="line">// 好友个人资料</span><br><span class="line">@property (nonatomic, strong) XMPPvCardAvatarModule *xmppvCardAvatarModule;</span><br></pre></td></tr></table></figure></p>
<p>3). 在MTStreamManager.m中懒加载xmppvCardTempModule,xmppvCardAvatarModule<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">// 自己的个人资料</span><br><span class="line">- (XMPPvCardTempModule *)xmppvCardTempModule &#123;</span><br><span class="line">    if (nil == _xmppvCardTempModule) &#123;</span><br><span class="line">        // 创建对象</span><br><span class="line">        _xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:[XMPPvCardCoreDataStorage sharedInstance] dispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppvCardTempModule;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 指定的用户的个人资料</span><br><span class="line">- (XMPPvCardAvatarModule *)xmppvCardAvatarModule &#123;</span><br><span class="line">    if (nil == _xmppvCardAvatarModule) &#123;</span><br><span class="line">        // 创建</span><br><span class="line">        _xmppvCardAvatarModule = [[XMPPvCardAvatarModule alloc] initWithvCardTempModule:_xmppvCardTempModule dispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppvCardAvatarModule;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>4). 在XMPPFramework.m中的activite方法中进行激活<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">// 激活其他模块</span><br><span class="line">- (void) activite &#123;</span><br><span class="line">    // 激活断线重连</span><br><span class="line">    [self.xmppReconnect activate:self.xmppStream];</span><br><span class="line">    // 激活心跳检测</span><br><span class="line">    [self.xmppAutoPing activate:self.xmppStream];</span><br><span class="line">    // 激活好友模块</span><br><span class="line">    [self.xmppRoster activate:self.xmppStream];</span><br><span class="line">    // 激活聊天模块</span><br><span class="line">    [self.xmppMessageArchiving activate:self.xmppStream];</span><br><span class="line">    // 激活个人资料</span><br><span class="line">    [self.xmppvCardTempModule activate:self.xmppStream];</span><br><span class="line">    // 好友的个人资料</span><br><span class="line">    [self.xmppvCardAvatarModule activate:self.xmppStream];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>5). 查询用户资料<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">@interface MTMeTableViewController () &lt;XMPPvCardTempModuleDelegate&gt;</span><br><span class="line">// 头像</span><br><span class="line">@property (weak, nonatomic) IBOutlet UIImageView *icon;</span><br><span class="line">// JID</span><br><span class="line">@property (weak, nonatomic) IBOutlet UILabel *name;</span><br><span class="line">// 昵称</span><br><span class="line">@property (weak, nonatomic) IBOutlet UILabel *nickName;</span><br><span class="line">// 个性签名</span><br><span class="line">@property (weak, nonatomic) IBOutlet UILabel *desc;</span><br><span class="line"></span><br><span class="line">// 内存存储个人信息</span><br><span class="line">@property (nonatomic, strong) XMPPvCardTemp *myvCardTemp;</span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTMeTableViewController</span><br><span class="line"></span><br><span class="line">// 懒加载获取存储数据</span><br><span class="line">- (XMPPvCardTemp *)myvCardTemp &#123;</span><br><span class="line">    if (nil == _myvCardTemp) &#123;</span><br><span class="line">        _myvCardTemp = [MTStreamManager sharedManager].xmppvCardTempModule.myvCardTemp;</span><br><span class="line">    &#125;</span><br><span class="line">    return _myvCardTemp;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (void)viewDidLoad &#123;</span><br><span class="line">    [super viewDidLoad];</span><br><span class="line">    // 设置代理,需要更新用户资料的界面都要实现这个代理</span><br><span class="line">    [[MTStreamManager sharedManager].xmppvCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];</span><br><span class="line">    // 设置参数</span><br><span class="line">    [self update];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 更新</span><br><span class="line">- (void)update &#123;</span><br><span class="line">    // 头像</span><br><span class="line">    self.icon.image = [UIImage imageWithData:self.myvCardTemp.photo];</span><br><span class="line">    // 名字</span><br><span class="line">    self.name.text = [MTStreamManager sharedManager].xmppStream.myJID.bare;</span><br><span class="line">    // 昵称</span><br><span class="line">    self.nickName.text = self.myvCardTemp.nickname;</span><br><span class="line">    // 个性签名</span><br><span class="line">    self.desc.text = self.myvCardTemp.description;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 更新，需要更新用户资料的界面都要实现这个代理</span><br><span class="line">- (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule &#123;</span><br><span class="line">    // 清除之前的内存</span><br><span class="line">    self.myvCardTemp = nil;</span><br><span class="line">    // 重新赋值最新的数据</span><br><span class="line">    [self update];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>6). 更新头像<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">// 点击头像时执行的方法</span><br><span class="line">// 选择照片--换头像    </span><br><span class="line">- (IBAction)pickerImage:(id)sender &#123;</span><br><span class="line">    // 相册</span><br><span class="line">    UIImagePickerController *picker = [[UIImagePickerController alloc] init];</span><br><span class="line">    // 参数设置</span><br><span class="line">    picker.allowsEditing = YES;</span><br><span class="line">    // 设置代理</span><br><span class="line">    picker.delegate = self;</span><br><span class="line">    // 弹出控制器</span><br><span class="line">    [self.navigationController presentViewController:picker animated:YES completion:nil];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 选中照片</span><br><span class="line">- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary&lt;NSString *,id&gt; *)info &#123;</span><br><span class="line">    NSLog(@&quot;info = %@&quot;, info);</span><br><span class="line">    // 获取图片</span><br><span class="line">    UIImage *image = info[UIImagePickerControllerEditedImage];</span><br><span class="line">    // 装换为二进制数据</span><br><span class="line">    NSData *imageData = UIImageJPEGRepresentation(image, 0.2);</span><br><span class="line">    // 内存存储</span><br><span class="line">    self.xmppvCardTemp.photo = imageData;</span><br><span class="line">    // 数据更新</span><br><span class="line">    [[MTStreamManager sharedManager].xmppvCardTempModule updateMyvCardTemp:self.xmppvCardTemp];</span><br><span class="line">    // 销毁控制器</span><br><span class="line">    [self.navigationController dismissViewControllerAnimated:YES completion:nil];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 取消选中</span><br><span class="line">- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker &#123;</span><br><span class="line">    // 销毁控制器</span><br><span class="line">    [self.navigationController dismissViewControllerAnimated:YES completion:nil];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>7). 更新昵称或者个性签名<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">@interface MTUpdateTableViewController ()</span><br><span class="line">// 信息输入框</span><br><span class="line">@property (weak, nonatomic) IBOutlet UITextField *textMessage;</span><br><span class="line">// 内存存储</span><br><span class="line">@property (nonatomic, strong) XMPPvCardTemp *myvCardTemp;</span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTUpdateTableViewController</span><br><span class="line"></span><br><span class="line">// 懒加载</span><br><span class="line">- (XMPPvCardTemp *)myvCardTemp &#123;</span><br><span class="line">    if (nil == _myvCardTemp) &#123;</span><br><span class="line">        _myvCardTemp = [MTStreamManager sharedManager].xmppvCardTempModule.myvCardTemp;</span><br><span class="line">    &#125;</span><br><span class="line">    return _myvCardTemp;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 取消按钮</span><br><span class="line">- (IBAction)cancel:(id)sender &#123;</span><br><span class="line">    // 关闭当前控制器</span><br><span class="line">    [self.navigationController popViewControllerAnimated:YES];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 更新数据</span><br><span class="line">- (IBAction)update:(id)sender &#123;</span><br><span class="line">    // 数据更新</span><br><span class="line">    if ([self.title isEqualToString:@&quot;昵称&quot;]) &#123;</span><br><span class="line">        // 对昵称做更新</span><br><span class="line">        self.myvCardTemp.nickname = self.textMessage.text;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        // 对个性签名做更新</span><br><span class="line">        self.myvCardTemp.description = self.textMessage.text;</span><br><span class="line">    &#125;</span><br><span class="line">    // 更新数据</span><br><span class="line">    [[MTStreamManager sharedManager].xmppvCardTempModule updateMyvCardTemp:self.myvCardTemp];</span><br><span class="line">    // 关闭当前控制器</span><br><span class="line">    [self.navigationController popViewControllerAnimated:YES];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####8. 群聊<br>1). 在XMPPFramework.h中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 群聊功能类</span><br><span class="line">#import &quot;XMPPMUC.h&quot;</span><br><span class="line">// 聊天室功能类</span><br><span class="line">#import &quot;XMPPRoom.h&quot;</span><br><span class="line">// 数据存储管理</span><br><span class="line">#import &quot;XMPPRoomCoreDataStorage.h&quot;</span><br></pre></td></tr></table></figure></p>
<p>2). 新建群聊管理类<br>MTMucRoomManager.h 头文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">@interface MTMucRoomManager : NSObject</span><br><span class="line">// 多用户聊天功能类</span><br><span class="line">@property (nonatomic, strong) XMPPMUC *xmppMuc;</span><br><span class="line">// 聊天室功能类</span><br><span class="line">@property (nonatomic, strong) XMPPRoom *xmppRoom;</span><br><span class="line"></span><br><span class="line">// 单例</span><br><span class="line">+ (instancetype)sharedMucRoom;</span><br><span class="line"></span><br><span class="line">// 加入或者创建聊天室</span><br><span class="line">- (void)joinOrCreateWithRoomJid:(XMPPJID *)roomJid andNickName:(NSString *)nickName;</span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>MTMucRoomManager.m 实现<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line">@interface MTMucRoomManager () &lt;XMPPMUCDelegate, XMPPRoomDelegate&gt;</span><br><span class="line"></span><br><span class="line">// 用来存储聊天室的字典</span><br><span class="line">@property (nonatomic, strong) NSMutableDictionary *roomDict;</span><br><span class="line"></span><br><span class="line">@end</span><br><span class="line"></span><br><span class="line">@implementation MTMucRoomManager</span><br><span class="line"></span><br><span class="line">static MTMucRoomManager *sInstance;</span><br><span class="line">// 单例</span><br><span class="line">+ (instancetype)sharedMucRoom &#123;</span><br><span class="line">    static dispatch_once_t onceToken;</span><br><span class="line">    dispatch_once(&amp;onceToken, ^&#123;</span><br><span class="line">        sInstance = [MTMucRoomManager new];</span><br><span class="line">    &#125;);</span><br><span class="line">    return sInstance;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 懒加载字典</span><br><span class="line">- (NSMutableDictionary *)roomDict &#123;</span><br><span class="line">    if (nil == _roomDict) &#123;</span><br><span class="line">        // 创建字典</span><br><span class="line">        _roomDict = [NSMutableDictionary dictionary];</span><br><span class="line">    &#125;</span><br><span class="line">    return _roomDict;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 多用户聊天功能类</span><br><span class="line">- (XMPPMUC *)xmppMuc &#123;</span><br><span class="line">    if (nil == _xmppMuc) &#123;</span><br><span class="line">        // 创建</span><br><span class="line">        _xmppMuc = [[XMPPMUC alloc] initWithDispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">        // 设置代理</span><br><span class="line">        [_xmppMuc addDelegate:self delegateQueue:dispatch_get_main_queue()];</span><br><span class="line">        // 激活</span><br><span class="line">        [_xmppMuc activate:[MTStreamManager sharedManager].xmppStream];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppMuc;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 聊天室功能类</span><br><span class="line">- (XMPPRoom *)xmppRoom &#123;</span><br><span class="line">    if (nil == _xmppRoom) &#123;</span><br><span class="line">        // 创建对象</span><br><span class="line">        _xmppRoom = [[XMPPRoom alloc] initWithDispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">    &#125;</span><br><span class="line">    return _xmppRoom;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 加入或者创建聊天室</span><br><span class="line">- (void)joinOrCreateWithRoomJid:(XMPPJID *)roomJid andNickName:(NSString *)nickName &#123;</span><br><span class="line">    // 创建房间</span><br><span class="line">    XMPPRoom *room = [[XMPPRoom alloc] initWithRoomStorage:[XMPPRoomCoreDataStorage sharedInstance] jid:roomJid dispatchQueue:dispatch_get_main_queue()];</span><br><span class="line">    // 激活</span><br><span class="line">    [room activate:[MTStreamManager sharedManager].xmppStream];</span><br><span class="line">    // 存放在字典中</span><br><span class="line">    self.roomDict[roomJid] = room;</span><br><span class="line">    // 加入房间</span><br><span class="line">    [room joinRoomUsingNickname:nickName history:nil];</span><br><span class="line">    // 设置代理</span><br><span class="line">    [room addDelegate:self delegateQueue:dispatch_get_main_queue()];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">#pragma mark 回调</span><br><span class="line">// 加入</span><br><span class="line">- (void)xmppRoomDidJoin:(XMPPRoom *)sender &#123;</span><br><span class="line">    // 对房间进行配置</span><br><span class="line">    [sender configureRoomUsingOptions:nil];</span><br><span class="line">    // 测试方法--需先要在控制台中创建分组与房间</span><br><span class="line">    XMPPJID *jid = [XMPPJID jidWithUser:@&quot;linghaoyu9&quot; domain:DO_MAIN resource:nil];</span><br><span class="line">    // 邀请加入</span><br><span class="line">    [sender inviteUser:jid withMessage:@&quot;来聊天&quot;];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 创建</span><br><span class="line">- (void)xmppRoomDidCreate:(XMPPRoom *)sender &#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@end</span><br></pre></td></tr></table></figure></p>
<p>3). 加入聊天室<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">XMPPJID *jid = [XMPPJID jidWithUser:@&quot;love&quot; domain:@&quot;tochat.mazaiting.com&quot; resource:nil];</span><br><span class="line">// 加入到房间</span><br><span class="line">[[MTMucRoomManager sharedMucRoom] joinOrCreateWithRoomJid:jid andNickName:@&quot;小鱼&quot;];</span><br></pre></td></tr></table></figure></p>
<p>4). 测试</p>
<ul>
<li>需要先在控制台中创建分组<br><img src="http://upload-images.jianshu.io/upload_images/3110861-41704530f307c687.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图12.jpg"></li>
<li>其次在控制台中创建分组<br><img src="http://upload-images.jianshu.io/upload_images/3110861-06356be41ed12033.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图13.jpg"></li>
<li>完成发消息</li>
</ul>
<p>####<a href="https://gitee.com/mazaiting/iOS-Study/tree/master/mac/XMPP" target="_blank" rel="noopener">示例地址</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/IM/Spark-登录Openfire(Windows)/" rel="next" title="Spark-登录Openfire(Windows)">
                <i class="fa fa-chevron-left"></i> Spark-登录Openfire(Windows)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/iOS/iOS-Downloader断点续传/" rel="prev" title="iOS-Downloader断点续传">
                iOS-Downloader断点续传 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
